import 'package:casdon/app_providers.dart';
import 'package:casdon/core/auth/auth_storage.dart';
import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';
import 'package:casdon/modules/home/data/api/ciot_device_api.dart';
import 'package:casdon/modules/home/data/repository/home_repository.dart';

class CiotDeviceListUsecase {
  final HomeRepository _repository;

  const CiotDeviceListUsecase(this._repository);

  Future<List<ResponseCiotDeviceApi>?> execute() async {
    try {
      Log.i("CiotDeviceListUsecase");
      final storage = getProvider(authStorageProvider.notifier);
      String token = await storage.getToken() ?? "NULL";
      Log.i("token: ${token}");
      var ret = await _repository.getCiotDeviceList();

      return ret;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("CiotDeviceListUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("CiotDeviceListUsecase 失败");
    }
  }
}
